<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>第二题</title>
    <script>
        window.onload = function () {
            var list = document.getElementsByName('lei');
            document.getElementById('chkAll').onclick = function () {
                for (var i = 0; i < list.length; i++) {
                    if (list[i].type == "checkbox") {
                        if (chkAll.checked == true) {
                            list[i].checked = true;
                        } else {
                            list[i].checked = false;
                        }
                    }
                }
            }
        }
    </script>
</head>
<body>

<table style = 'text-align:center;width:500px;border-collapse:collapse;border:1px solid #efefef' border = 1>
    <tr>
        <th style = 'width:20%' title = '全选'>全选<input id="chkAll" type = 'checkbox' name="lei" /></th>
        <th style = 'width:30%'>姓名</th>
        <th style = 'width:60%'>地址</th>
    </tr>
    <tr>
        <td><input type = 'checkbox' name="lei" /></td>
        <td>张三</td>
        <td><input type = 'text' /></td>
    </tr>
    <tr>
        <td><input type = 'checkbox' name="lei" /></td>
        <td>李四</td>
        <td><input type = 'text' /></td>
    </tr>
</table>
<hr/>
    <p>代码示例</p>
    <pre>
          &lt;script&gt;
          window.onload = function () {
            var list = document.getElementsByName('lei');
            document.getElementById('chkAll').onclick = function () {
                for (var i = 0; i < list.length; i++) {
                    if (list[i].type == "checkbox") {
                        if (chkAll.checked == true) {
                            list[i].checked = true;
                        } else {
                            list[i].checked = false;
                        }
                    }
                }
            }
        }

    &lt;/script&gt;

    </pre>

</body>
</html>